package cn.ymatrix.Feishu;

import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.JSON;

import java.util.HashMap;
import java.util.Map;

// 飞书API参考：https://open.feishu.cn/document/ukTMukTMukTM/ucTM5YjL3ETO24yNxkjN
public class FeishuSendMessage {

    public static void main(String[] args) {
        sendMessage("这个飞书群发消息测试");
    }

    public static final String WebHookUrl =
            "https://open.feishu.cn/open-apis/bot/v2/hook/xxxxxxxxxx";

    public static void sendMessage(String msg) {
        //请求的JSON数据，这里用map在工具类里转成json格式
        Map<String, Object> json = new HashMap();
        Map<String, Object> text = new HashMap();
        json.put("msg_type", "text");
        text.put("text", "飞书告警通知：" + msg);
        json.put("content", text);
        //发送post请求
        String result = HttpRequest.post(WebHookUrl).body(JSON.toJSONString(json), "application/json;charset=UTF-8").execute().body();
        System.out.println(result);

    }
}
